package ai.people.netmon.msgsearch.controller;


import ai.people.netmon.framework.domain.social.user.SocialAccountSearchReqVO;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.msgsearch.domain.entity.SocialUser;
import ai.people.netmon.msgsearch.service.ISocialUserEsSearchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 社交媒体账号查询相关接口
 * @author LiGuanNan
 * @date 2022/5/31 下午2:23
 */
@RestController
@RequestMapping("v1/social-user")
public class SocialUserSearchController {

    @Autowired
    private ISocialUserEsSearchService socialUserEsSearchService;

    /**
     * 社交媒体数据查询
     *
     * @param reqParam 请求参数
     * @return {@link Result}<{@link SocialUser}<{@link SocialUser}>>
     */
    @PostMapping("/search")
    public Result<PageResponse<SocialUser>> search(@Validated @RequestBody SocialAccountSearchReqVO reqParam) {
        if(StringUtils.isBlank(reqParam.getSearchKeywords())){
            return ResultUtil.success(PageResponse.builderEmpty());
        }
        return ResultUtil.success(socialUserEsSearchService.queryPage(reqParam));
    }

    /**
     * 社交媒体账号详情
     *
     * @return {@link Result}<{@link SocialUser}<{@link SocialUser}>>
     */
    @PostMapping("/detail/{source}/{id}")
    public Result<SocialUser> detail(@PathVariable("source") String source, @PathVariable("id") String id) {
        if(StringUtils.isBlank(source) || StringUtils.isBlank(id)){
            return ResultUtil.success(PageResponse.builderEmpty());
        }
        return ResultUtil.success(socialUserEsSearchService.detail(id, source));
    }

}
